
import { axiosError, defaultErrorMessage } from 'src/util/errorHandler';
import http from 'src/util/http';
import qs from 'qs'
import moment from 'moment'

type PostAuthMeRequest = any
type PostAuthMeResponse = any


// 获取充值地址getMyRechargeAddres用户ID[guid]用户授权后的token值
const getMyRechargeAddres = async (data: PostAuthMeRequest) => {
    try {
        return await http.post<PostAuthMeResponse, PostAuthMeRequest>(`Money/getMyRechargeAddres?FUserID=${data.FUserID}&token=${data.token}`);
    } catch (e) {
        const error = axiosError(e);
        throw defaultErrorMessage(error);
    }
};

// 读取提现列表
const getMyWithdraw = async (data: PostAuthMeRequest) => {
    try {
        return await http.post<PostAuthMeResponse, PostAuthMeRequest>(`Money/getMyWithdraw?FUserID=${data.FUserID}&FType=${data.FType}&Sdate=${moment(data.Sdate).format('YYYY-MM-DD HH:mm:ss')}&Edate=${moment(data.Edate).format('YYYY-MM-DD HH:mm:ss')}&token=${data.token}`);
    } catch (e) {
        const error = axiosError(e);
        throw defaultErrorMessage(error);
    }
};
// 读取充值列表
const getMyRecharge = async (data: PostAuthMeRequest) => {
    try {
        return await http.post<PostAuthMeResponse, PostAuthMeRequest>(`Money/getMyRecharge?FUserID=${data.FUserID}&FType=${data.FType}&Sdate=${moment(data.Sdate).format('YYYY-MM-DD HH:mm:ss')}&Edate=${moment(data.Edate).format('YYYY-MM-DD HH:mm:ss')}&token=${data.token}`);
    } catch (e) {
        const error = axiosError(e);
        throw defaultErrorMessage(error);
    }
};
// 新增地址管理
const addMyAddress = async (dataParam: PostAuthMeRequest) => {
    const data = qs.stringify(dataParam)
    try {
        return await http.post<PostAuthMeResponse, PostAuthMeRequest>(`Money/AddMyAddress`, { data });
    } catch (e) {
        const error = axiosError(e);
        throw defaultErrorMessage(error);
    }
};
// 删除地址管理
const delMyAddress = async (data: PostAuthMeRequest) => {
    try {
        return await http.post<PostAuthMeResponse, PostAuthMeRequest>(`Money/DelMyAddress?FID=${data.FID}&token=${data.token}`);
    } catch (e) {
        const error = axiosError(e);
        throw defaultErrorMessage(error);
    }
};
// 读取地址列表
const getMyAddress = async (data: PostAuthMeRequest) => {
    try {
        return await http.post<PostAuthMeResponse, PostAuthMeRequest>(`Money/getMyAddress?FUserID=${data.FUserID}&token=${data.token}`);
    } catch (e) {
        const error = axiosError(e);
        throw defaultErrorMessage(error);
    }
};

// 发起提现申请
const addWithdraw = async (dataParam: PostAuthMeRequest) => {
    const data = qs.stringify(dataParam)
    try {
        return await http.post<PostAuthMeResponse, PostAuthMeRequest>(`Money/AddWithdraw `, { data });
    } catch (e) {
        const error = axiosError(e);
        throw defaultErrorMessage(error);
    }
};

const getUserReport = async (data: PostAuthMeRequest) => {
    try {
        return await http.get<PostAuthMeResponse, PostAuthMeRequest>(`Money/getUserReport?FUserID=${data.FUserID}&Sdate=${moment(data.Sdate).format('YYYY-MM-DD HH:mm:ss')}&Edate=${moment(data.Edate).format('YYYY-MM-DD HH:mm:ss')}&token=${data.token}`);
    } catch (e) {
        const error = axiosError(e);
        throw defaultErrorMessage(error);
    }
};
export default {
    getMyRechargeAddres,
    getMyWithdraw,
    getMyRecharge,
    addMyAddress,
    delMyAddress,
    getMyAddress,
    addWithdraw,
    getUserReport
};
